#ifndef POINTFP_H_INCLUDED
#define POINTFP_H_INCLUDED

#include "FPmath.h"

struct PointFP {

  Fixed x,y;

  PointFP() : x(0),y(0) {}
  PointFP(const Fixed& X, const Fixed& Y) : x(X), y(Y) {}

  PointFP& operator =( const PointFP& p) {x=p.x; y=p.y; return *this;}

  PointFP operator +(const PointFP& p) const {return PointFP(x+p.x,y+p.y);}
  PointFP& operator +=(PointFP p) {*this = *this + p; return *this;}

  PointFP operator -(const PointFP& p) const {return PointFP(x-p.x,y-p.y);}
  PointFP& operator -=(PointFP p) {*this = *this - p; return *this;}

  PointFP operator *(const Fixed& s) const {return PointFP(x*s,y*s);}
  PointFP& operator *=(Fixed s) {*this = *this * s; return *this;}
  //Dot Product
  Fixed operator *(const PointFP& p) const {return (x*p.x + y*p.y);}

  PointFP operator /(const Fixed& s) const {return PointFP(x/s,y/s);}
  PointFP& operator /=(Fixed s) {*this = *this / s; return *this;}

  Fixed length() const { return FPmath::sqrt(lengthSq()); }
  Fixed lengthSq() const { return (x * x) + (y * y); }

  PointFP& normalize() { Fixed l=length(); return l==0?(*this):(*this/=l); }

};

extern inline PointFP operator *(const Fixed& x, const PointFP& p) { return p*x; }


#endif // POINTFP_H_INCLUDED
